package com.damei.qmui_test_demo.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.damei.qmui_test_demo.R;
import com.damei.qmui_test_demo.activity.home.DataListActivity;
import com.damei.qmui_test_demo.httpService.HttpManager;
import com.damei.qmui_test_demo.httpService.HttpStringResponseHandler;
import com.damei.qmui_test_demo.model.MeiZiResponse;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 首页
 */
public class HomeActivity extends Fragment {

    @BindView(R.id.refreshLayout)
    RefreshLayout refreshLayout;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_home, container, false);
        ButterKnife.bind(this, view);
        initRecycerView();
        return view;
    }

    /**
     * 初始化加载
     */
    private void initRecycerView() {
        Log.e("HomeActivity----------", "1");

        refreshLayout.setPrimaryColors(Color.parseColor("#93091E"));
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(2000/*,false*/);
            }
        });
//        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshlayout) {
//                refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
//            }
//        });
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.e("HomeActivity----------", "3");
    }

    @OnClick(R.id.top_card_bg)
    public void onCreate() {
        startActivity(new Intent(getActivity(), DataListActivity.class));
    }
}
